package com.xzmzhp.dao.activity.SQL;

import com.xzmzhp.utils.DateUtil;
import com.xzmzhp.utils.StringUtils;
import org.apache.ibatis.jdbc.SQL;

import java.util.Date;
import java.util.Map;

/**
 * @author: 王源(xm)
 * @create: 2022-04-01 19:05
 * @program: ams
 * @description: 活动管理sql
 */
public class ActivitySql {

    public String findByParam(Map<String,Object> param){
        //获取参数
        Integer societyId = Integer.parseInt(param.get("societyId").toString());
        String activityName =  param.get("activityName").toString();
        Date startTime = DateUtil.getDateTime(DateUtil.FORMAT_SHORT,param.get("startTime").toString());
        Date endTime =  DateUtil.getDateTime(DateUtil.FORMAT_SHORT,param.get("endTime").toString());
        return new SQL(){
            {
                SELECT("activity_id,activity_name,activity_date,activity.society_id,society_name");
                FROM("activity,society");
                if (StringUtils.isNotNull(activityName)){
                    WHERE("activity_name ='"+activityName+"'");
                }
                if (StringUtils.isNotNull(societyId)){
                    WHERE("activity.society_id ="+societyId);
                }
                if (StringUtils.isNotNull(startTime)){
                    WHERE("activity_date >='"+startTime+"'");
                }
                if (StringUtils.isNotNull(endTime)){
                    WHERE("activity_date >='"+endTime+"'");
                }
                ORDER_BY("activity_date");

            }
        }.toString();
    }
}
